﻿
@model Rehabilitation.Models.Test

@using Rehabilitation.Models

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<fieldset>
    <legend>Test</legend>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.PatientID)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.PatientID)
    </div>

    <div class="display-label">
         User
    </div>
    <div class="display-field">
        @(((User)ViewBag.User).UserName)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.TestDate)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.TestDate)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Location)
    </div>
    <div class="display-field">
        @(((Location)ViewBag.Location).DisplayName)
    </div>

    
</fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new { id=Model.TestID }) |
    @Html.ActionLink("Back to Patient", "Details", "Patients", new{id=Model.PatientID}, null)
</p>

<p>Test Details</p>
<div>
    @using (Html.BeginForm("SaveDetails", "Test", FormMethod.Post))
    {
        List<string> resultStrs = new List<string>() { "0", "1", "2", "3", "4", "5", "6", "_1", "_2", "_3" }; 
        <text>
            @Html.HiddenFor(model => model.TestID)
        </text>
    if (ViewBag.TestDetails != null && ((List<TestDetail>)ViewBag.TestDetails).Any())
        {
            List<TestDetail> tds = (List<TestDetail>)ViewBag.TestDetails;
            TestDetail t0 = tds.SingleOrDefault(t => t.TestSequence == 0);
            TestDetail t1 = tds.SingleOrDefault(t => t.TestSequence == 1);
            TestDetail t2 = tds.SingleOrDefault(t => t.TestSequence == 2);
            TestDetail t3 = tds.SingleOrDefault(t => t.TestSequence == 3);
            TestDetail t4 = tds.SingleOrDefault(t => t.TestSequence == 4);
            TestDetail t5 = tds.SingleOrDefault(t => t.TestSequence == 5);
            TestDetail t6 = tds.SingleOrDefault(t => t.TestSequence == 6);
            TestDetail t_1 = tds.SingleOrDefault(t => t.TestSequence == -1);
            TestDetail t_2 = tds.SingleOrDefault(t => t.TestSequence == -2);
            TestDetail t_3 = tds.SingleOrDefault(t => t.TestSequence == -3);
            List<TestDetail> results = new List<TestDetail>(){t0, t1,t2,t3,t4,t5,t6,t_1, t_2,t_3};
            
            
            <text>

                
                <table class="full">
                    <thead>
                        <tr>
                            <th>Test Period</th>
                            <th>Time</th>
                            <th>SpO2</th>
                            <th>HR</th>
                            <th>Oxygen</th>
                            <th>Rest(s)</th>
                            <th>BORG -- Client's
                                <br />
                                presentation/symptoms</th>
                            <th>Comments</th>
                        </tr>
                    </thead>
                    <tbody>
                        @for(int i = 0; i<10; i++)
                        {
                            bool needLine = (i == 0 || i == 6);
                            string minutes = i == 0 ? "" : i > 0 && i < 7 ? i + "&nbsp;min" : i - 6 + "&nbsp;min";
                            <text>
                                <tr @(needLine?"style=\"border-bottom: 1px solid black\"":"")>
                                    <td>@(i==0?"Prior to Test":i==1?"Test in pgogress":i==7?"Post test/recovery":"")</td>
                                    <td>@Html.Raw(minutes)</td>
                                    <td>@Html.TextBox("SpO2"+resultStrs[i], results[i]==null?"":""+ results[i].SpO2)</td>
                                    <td>@Html.TextBox("HR"+resultStrs[i], results[i]==null?"":""+ results[i].HR)</td>
                                    <td>@Html.TextBox("Oxygen"+resultStrs[i], results[i]==null?"":""+ results[i].Oxygen)</td>
                                    <td>@Html.TextBox("Rest"+resultStrs[i], results[i]==null?"":""+ results[i].Rest)</td>
                                    <td>@Html.TextBox("BORG"+resultStrs[i], results[i]==null?"":""+ results[i].BORG)</td>
                                    <td>@Html.TextBox("Comments"+resultStrs[i], results[i]==null?"":""+ results[i].Comments)</td>
                                </tr>
                            </text>
                        }
                    </tbody>
                </table>
            </text>
        
        }
        else
        {
             <text>
        <table class="full">
            <thead>
                <tr>
                    <th>Test Period</th>
                    <th>Time</th>
                    <th>SpO2</th>
                    <th>HR</th>
                    <th>Oxygen</th>
                    <th>Rest(s)</th>
                    <th>BORG -- Client's
                        <br />
                        presentation/symptoms</th>
                    <th>Comments</th>
                </tr>
            </thead>
            <tbody>
                @for(int i = 0; i<10; i++)
                {
                    bool needLine = (i == 0 || i == 6);
                    string minutes = i == 0 ? "" : i > 0 && i < 7 ? i + "&nbsp;min" : i - 6 + "&nbsp;min";
                    <text>
                        <tr @Html.Raw(needLine?"style=\"border-bottom: 1px solid black\"":"")>
                            <td>@(i==0?"Prior to Test":i==1?"Test in pgogress":i==7?"Post test/recovery":"")</td>
                            <td>@Html.Raw(minutes)</td>
                            <td>@Html.TextBox("SpO2"+resultStrs[i])</td>
                            <td>@Html.TextBox("HR"+resultStrs[i])</td>
                            <td>@Html.TextBox("Oxygen"+resultStrs[i])</td>
                            <td>@Html.TextBox("Rest"+resultStrs[i])</td>
                            <td>@Html.TextBox("BORG"+resultStrs[i])</td>
                            <td>@Html.TextBox("Comments"+resultStrs[i])</td>
                        </tr>
                    </text>
                }
            </tbody>
        </table>
        </text>
        }
        <text>
            <input type="submit" value="Save"/>
        </text>
    }
</div>
